﻿using IBLL;
using IDAL;
using Model;
using Model.DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BLL
{
    public class HouseTypeBLL : HouseTypeIBLL
    {
        public HouseTypeBLL(IBaseDAL<HouseType>Db)
        {
            this.Db = Db;
        }

        public IBaseDAL<HouseType> Db { get; }

        public async Task<int> Add(HouseType d)
        {
            bool s = Db.GetAll().Any(x => x.HouseTypeName == d.HouseTypeName);
            if (!s)
            {
                return await Db.AddAsync(d);
            }
            else
            {
                return -1;
            }
                
        }

        public HouseTypeDTO Show(string? name, double? min, double? max, int pageIndex, int pageSize)
        {
            var q = Db.GetAll();
            if (!string.IsNullOrEmpty(name))
            { 
                q = q.Where(x => x.HouseTypeName.Contains(name));
            }
            HouseTypeDTO Fl = new HouseTypeDTO();
            Fl.Count = q.Count();
            Fl.tangPage =q.OrderBy(x=>x.HouseTypeId).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
            return Fl;
        }

        public IQueryable<HouseType> ShowAll()
        {
            return Db.GetAll();
        }
    }
}
